﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OrderAggregator.DataStorage;


namespace OrderAggregator.Core
{
    /// <summary>
    /// Позиция заказа в цех
    /// </summary>
    public class DepartmetOrderRow
    {
        private readonly Storage.ProductRow _product;
        private readonly int _number;

        public DepartmetOrderRow(int number, Storage.ProductRow product)
        {
            _number = number;
            _product = product;

            Count = 0;
        }

        public int Number
        {
            get { return _number; }
        }

        /// <summary>
        /// Продукт
        /// </summary>
        public Storage.ProductRow Product
        {
            get
            {
                return _product;
            }
        }

        /// <summary>
        /// Кол-во (условные ед.)
        /// </summary>
        public decimal Count
        {
            get; set;
        }


        /// <summary>
        /// Кол-во (форматированое)
        /// </summary>
        public string CountString
        {
            get
            {
                if (!string.IsNullOrEmpty(UnitName))
                {
                    if (UnitName.StartsWith(InputFormats.BaseOrderFormat.UnitKg, StringComparison.InvariantCultureIgnoreCase))
                    {
                        return Count.ToString("0.0", AggregatorConfig.RuCulture);
                    }
                    else if (UnitName.StartsWith(InputFormats.BaseOrderFormat.UnitPcs, StringComparison.InvariantCultureIgnoreCase))
                    {
                        return Count.ToString("0", AggregatorConfig.RuCulture);
                    }
                }
                
                if (Math.Round(Count) == Count)
                {
                    return Count.ToString("0", AggregatorConfig.RuCulture);
                }

                return Count.ToString();
            }
        }

        /// <summary>
        /// Ед.измр
        /// </summary>
        public string UnitName
        {
            get; set;
        }
    }
}
